using System;

using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;

namespace Abp.EntityFrameworkCore.Dapper.Tests.Domain;

public class Blog : AggregateRoot, IHasCreationTime
{
    public Blog()
    {
    }

    public Blog(string name, string url)
    {
        if (string.IsNullOrWhiteSpace(name))
        {
            throw new ArgumentNullException(nameof(name));
        }

        if (string.IsNullOrWhiteSpace(url))
        {
            throw new ArgumentNullException(nameof(url));
        }

        Name = name;
        Url = url;
    }

    public string Name { get; set; }

    public string Url { get; protected set; }

    public DateTime CreationTime { get; set; }

    public void ChangeUrl(string url)
    {
        if (string.IsNullOrWhiteSpace(url))
        {
            throw new ArgumentNullException(nameof(url));
        }

        string oldUrl = Url;
        Url = url;

        DomainEvents.Add(new BlogUrlChangedEventData(this, oldUrl));
    }
}